package com.example.appointment.wxapi;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Toast;

import com.example.appointment.AppointmentApplication;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;

/**
 * Created by Admin on 2016/9/16.
 */
public class WXEntryActivity extends Activity implements IWXAPIEventHandler {

    private Context context = WXEntryActivity.this;

    private void handleIntent(Intent paramIntent) {
        AppointmentApplication.api.handleIntent(paramIntent, this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        handleIntent(intent);
    }

    @Override
    public void onResp(BaseResp baseResp) {
        switch (baseResp.errCode) {
            case BaseResp.ErrCode.ERR_OK:
                if (ConstantsAPI.COMMAND_SENDMESSAGE_TO_WX == baseResp.getType()) {
                    Toast.makeText(context, "分享成功", Toast.LENGTH_LONG).show();
                    break;
                }
                String code = ((SendAuth.Resp) baseResp).code;
//                new SharedPreferencesclass(49, code, context);
                System.out.println("微信确认登录返回的code：" + code);
                Toast.makeText(context, "微信确认登录返回的code：" + code, Toast.LENGTH_LONG).show();
//                MyResumeLoginView.loginHandler.sendEmptyMessage(MyResumeLoginView.WEIXIN_LOGIN_SUCCESS);
                break;
            case BaseResp.ErrCode.ERR_USER_CANCEL:
                break;
            case BaseResp.ErrCode.ERR_AUTH_DENIED:
                break;
            default:
                break;
        }
        finish();
    }

    @Override
    public void onReq(BaseReq baseReq) {
        finish();
    }
}
